package com.dgut.hisystem.controller;

import com.dgut.hisystem.entity.Register;
import com.dgut.hisystem.service.RegisterService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.sql.Date;
import java.sql.Timestamp;
import java.time.LocalDateTime;

@RequestMapping("/register")
@RestController
public class RegisterController {
    @Resource
    private RegisterService registerService;

    @RequestMapping("/get")
    Register getRegisterById(long id) {
        return registerService.getRegisterById(id);
    }

    @RequestMapping("/insert")
    void insert(String ys_id, String appoint_day) {
        Register register = new Register();
        register.setYs_id(Long.parseLong(ys_id));
        String[] time = appoint_day.split("-");
        Timestamp timestamp = Timestamp.valueOf(LocalDateTime.of(Integer.parseInt(time[0]), Integer.parseInt(time[1]), Integer.parseInt(time[2]), 0, 0, 0));
        register.setGh_datetime(timestamp);

        register.setBr_card(807424860);
        register.setGh_illness("生病");

        registerService.insert(register);
    }

    @RequestMapping("/update")
    void update(@RequestBody Register register) {
        registerService.update(register);
    }

    @RequestMapping("/delete")
    void delete(long id) {
        registerService.delete(id);
    }



}
